home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / prospero / propsero.lha / prospero-beta.4.2e / user / vls.c < prev    next >
C/C++ Source or Header  |  1992-02-10  |  6KB  |  234 lines

  1. /*
  2.  * Copyright (c) 1989, 1990, 1991 by the University of Washington
  3.  *
  4.  * For copying and distribution information, please see the file
  5.  * <uw-copyright.h>.
  6.  */
  7.  
  8. #include <uw-copyright.h>
  9. #include <stdio.h>
  10.  
  11. #include <pfs.h>
  12. #include <perrno.h>
  13.  
  14. int    perrno;
  15. int    pfs_debug = 0;
  16.  
  17. PATTRIB        pget_at();
  18.  
  19. main(argc,argv)
  20.     int        argc;
  21.     char    *argv[];
  22.     {
  23.     VDIR_ST        dir_st;
  24.     VDIR        dir= &dir_st;
  25.     VLINK        l;
  26.     VLINK        replica;
  27.     int        flags = 0;
  28.     int        verbose = 0;
  29.     int        dmagic = 0;
  30.     int        show_failed = 0;
  31.     int        show_at = 0;
  32.     int        replica_flag = 0;
  33.     int        conflict_flag = 0;
  34.     int        tmp;
  35.     char        at_name[40];
  36.     char        *progname = argv[0];
  37.  
  38.     flags = GVD_LREMEXP;
  39.  
  40.     vdir_init(dir);
  41.  
  42.     argc--;argv++;
  43.  
  44.     while (argc > 0 && **argv == '-') {
  45.         switch (*(argv[0]+1)) {
  46.         
  47.         case 'a':  /* Show attributes */
  48.         show_at = 1; 
  49.         verbose = 1;
  50.         tmp = sscanf(argv[0],"-a%s",at_name);
  51.         if((tmp < 1) || (*at_name == '\0'))  strcpy(at_name,"ALL");
  52.         break;
  53.  
  54.         case 'A':  /* Show only link attributes */
  55.         show_at = 2; /* Show only link attributes */
  56.         verbose = 1;
  57.         tmp = sscanf(argv[0],"-a%s",at_name);
  58.         if((tmp < 1) || (*at_name == '\0'))  strcpy(at_name,"ALL");
  59.         break;
  60.  
  61.         case 'c':  /* Show conflicting links */
  62.         conflict_flag++;
  63.         break;
  64.  
  65.         case 'D':  /* Debug level */
  66.         pfs_debug = 1; /* Default debug level */
  67.         sscanf(argv[0],"-D%d",&pfs_debug);
  68.         break;
  69.  
  70.         case 'f':  /* Show failed links */
  71.         show_failed++;
  72.         break;
  73.  
  74.         case 'm':  /* Display magic number */
  75.         dmagic++;
  76.         break;
  77.  
  78.         case 'r':  /* Show replicas */
  79.         replica_flag++;
  80.         break;
  81.  
  82.         case 'u':  /* Do not expand union links */
  83.         flags = GVD_UNION;
  84.         break;
  85.  
  86.         case 'v':  /* Display link on more than one line (verbose) */
  87.         verbose = 1;
  88.         break;
  89.  
  90.         default:
  91.         fprintf(stderr,
  92.             "Usage: vls [-a,-c,-r,-u,-v] <file or directory name>\n");
  93.         exit(1);
  94.         }
  95.         argc--, argv++;
  96.     }
  97.  
  98.     if(show_at) flags |= GVD_ATTRIB;
  99.  
  100.     if (argc > 1) {
  101.         fprintf(stderr,
  102.             "Usage: vls [-a,-c,-r,-u,-v] <file or directory name>\n");
  103.         exit(1);
  104.     }
  105.  
  106.     tmp = rd_vdir((argc == 1 ? argv[0] : ""),0,dir,flags);
  107.  
  108.     if(tmp && (tmp != DIRSRV_NOT_DIRECTORY)) {
  109.         fprintf(stderr,"%s",progname);
  110.         perrmesg(" failed: ", tmp, NULL);
  111.         exit(1);
  112.     }
  113.  
  114.     if(pwarn) pwarnmesg("WARNING: ",0,NULL);
  115.  
  116.     l = dir->links;
  117.  
  118.     while(l) {
  119.         display_link(l,dmagic,verbose,show_at,at_name);
  120.         replica = l->replicas;
  121.         while(replica) {
  122.         if((replica_flag && (l->f_magic_no != 0) && 
  123.             (l->f_magic_no == replica->f_magic_no)) || conflict_flag)
  124.             display_link(replica,
  125.              (dmagic || (l->f_magic_no != replica->f_magic_no)),
  126.              verbose,show_at,at_name);
  127.         replica = replica->next;
  128.         }
  129.         l = l->next;
  130.     }
  131.  
  132.     l = dir->ulinks;
  133.  
  134.     if((tmp != DIRSRV_NOT_DIRECTORY) || show_failed) {
  135.         while(l) {
  136.         if((l->expanded == FALSE) || (l->expanded == FAILED))
  137.         display_link(l,dmagic,verbose,show_at,at_name);
  138.         l = l->next;
  139.         }
  140.     }
  141.  
  142.     vllfree(dir->links);
  143.     exit(0);
  144.  
  145.     }
  146.  
  147.  
  148. display_link(l,dmagic,verbose,show_at,at_name)
  149.     VLINK    l;
  150.     int        dmagic;
  151.     int        verbose;
  152.     int        show_at;
  153.     char    *at_name;
  154.     {
  155.     VLINK        fil;
  156.     PATTRIB     ap;
  157.     char        linkname[MAX_VPATH];
  158.  
  159.     
  160.     if(l->linktype == '-') return;
  161.  
  162.     if(dmagic) sprintf(linkname,"%s#%d",l->name,l->f_magic_no);
  163.     else strcpy(linkname,l->name);
  164.  
  165.     if (verbose) {
  166.         printf("\n      Name: %s\n",l->name);
  167.         printf("   ObjType: %s\n",l->type);
  168.         printf("  LinkType: %s\n",((l->linktype == 'U') ? "Union" : "Standard"));
  169.         printf("  HostType: %s\n",l->hosttype);
  170.         printf("      Host: %s\n",l->host);
  171.         printf("  NameType: %s\n",l->nametype);
  172.         printf("  Pathname: %s\n",l->filename);
  173.         if(l->version) printf("   Version: %d\n",l->version);
  174.         if(dmagic || l->f_magic_no) 
  175.         printf("     Magic: %d\n",l->f_magic_no);
  176.  
  177.         if(show_at) {
  178.         /* If only link attributes, then use l->lattrib */
  179.         /* otherwise get attribues for object.          */
  180.         if(show_at == 2) ap = l->lattrib;
  181.         else {
  182.             /* Eventually we will merge the link attributes with  */
  183.             /* the object attribues based on the precedence field,*/
  184.             /* but for now, if attributes are retruend for the    */
  185.             /* object we use them, otherwisseise we use those     */
  186.             /* associated with the link                           */
  187.             ap = pget_at(l,at_name);
  188.             if(!ap) ap = l->lattrib;
  189.         }
  190.         if(ap) {
  191.             printf("Attributes:\n\n");
  192.             while(ap) {
  193.             printf("%15s: ",ap->aname);
  194.             if(strcmp(ap->avtype,"ASCII") == 0)
  195.                 printf("%s\n",ap->value.ascii);
  196.             else if(strcmp(ap->avtype,"LINK") == 0)
  197.                 printf("%s %s %s %d %d\n",
  198.                    ap->value.link->name,ap->value.link->host,
  199.                    ap->value.link->filename,
  200.                    ap->value.link->version, 
  201.                    ap->value.link->f_magic_no);
  202.             else printf("<unknown-type %s>\n",ap->avtype);
  203.             ap = ap->next;
  204.             }
  205.             if(l->filters) printf("\n");
  206.         }
  207.         atlfree(ap);
  208.         }
  209.  
  210.         if(l->filters) {
  211.         printf("   Filters: \n");
  212.         fil = l->filters;
  213.         while(fil) {
  214.             printf("\n      HostType: %s\n",fil->hosttype);
  215.             printf("          Host: %s\n",fil->host);
  216.             printf("      NameType: %s\n",fil->nametype);
  217.             printf("      Pathname: %s\n",fil->filename);
  218.             if(fil->f_magic_no) 
  219.             printf("         Magic: %d\n",fil->f_magic_no);
  220.             if(fil->args) printf("          Args: %s\n",fil->args);
  221.             fil = fil->next;
  222.         }
  223.         }
  224.         printf("\n");
  225.     }
  226.     else printf("%c%c %-20.20s %c%-15.15s %-38.38s\n",
  227.             ((l->linktype == 'L') ? ' ' : l->linktype),
  228.             (l->expanded ? 'F' : ' '),
  229.             linkname,
  230.             (l->filters ? '*' : ' '),
  231.             l->host,l->filename);
  232.     
  233.     }
  234.